import org.kie.api.KieServices;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.builder.model.KieBaseModel;
import org.kie.api.builder.model.KieModuleModel;
import org.kie.api.builder.model.KieSessionModel;
import org.kie.api.conf.EqualityBehaviorOption;
import org.kie.api.conf.EventProcessingOption;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.conf.ClockTypeOption;

/**
 * $END$
 *
 * @author zjk
 * @datetime 2021/12/21 14:09
 */
public class KModuleGenerator {


    public void generate(){
        KieServices kieServices = KieServices.Factory.get();
        KieModuleModel kieModuleModel = kieServices.newKieModuleModel();

        KieBaseModel kieBaseModel1 = kieModuleModel.newKieBaseModel( "KBase1 ")
                .setDefault( true )
                .setEqualsBehavior( EqualityBehaviorOption.EQUALITY )
                .setEventProcessingMode( EventProcessingOption.STREAM );

        KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel( "KSession1" )
                .setDefault( true )
                .setType( KieSessionModel.KieSessionType.STATEFUL )
                .setClockType( ClockTypeOption.get("realtime") );

        KieFileSystem kfs = kieServices.newKieFileSystem();
        kfs.writeKModuleXML(kieModuleModel.toXML());
    }


    public void addArtifacts (){
        KieServices kieServices = KieServices.Factory.get();
        KieFileSystem kfs = kieServices.newKieFileSystem();
//        kfs.write( "src/main/resources/KBase1/ruleSet1.drl", stringContainingAValidDRL )
//                .write( "src/main/resources/dtable.xls",
//                        kieServices.getResources().newInputStreamResource( dtableFileStream ).setResourceType(ResourceType.DRL)  );
//
//        KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
//        assertEquals( 0, kieBuilder.getResults().getMessages( Message.Level.ERROR ).size() );

        KieContainer kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
    }
}
